<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
    <script src="../js/lay-module/http/http.js"></script>
</head>
<body onload="init()">
<div class="layui-form layuimini-form">
    <div class="layui-form-item" hidden>
        <label class="layui-form-label required">单位Id</label>
        <div class="layui-input-block">
            <input type="text" name="id"  id="id" value="" class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">单位名称</label>
        <div class="layui-input-block">
            <input type="text" name="name"  id="name" value="" placeholder="请输入单位名称" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">组织机构代码</label>
        <div class="layui-input-block">
            <input type="text" id="code" name="code" value="" placeholder="请输入组织机构代码" class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">账号</label>
        <div class="layui-input-block">
            <input type="text" id="username" name="username" value="" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">密码</label>
        <div class="layui-input-block">
            <input type="text" id="password" name="password" placeholder="请输入密码" value="" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">联系信息</label>
        <div class="layui-input-block">
            <input type="text" id="phone" name="phone" value="" placeholder="请输入联系信息" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">经济财务数据</label>
        <div class="layui-input-block">
            <input type="text" id="economics" name="economics" value="" placeholder="请输入经济财务数据" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">单位资质</label>
        <div class="layui-input-block">
            <input type="text" id="certification" name="certification" placeholder="请输入单位资质" value="" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">资质是否验证</label>
        <div class="layui-input-block">
            <input type="text" id="verify" name="verify" value="" class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">市级资金</label>
        <div class="layui-input-block">
            <input type="text" id="municipalMoney" name="municipalMoney" placeholder="请输入市级资金" value="" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">上级资金</label>
        <div class="layui-input-block">
            <input type="text" id="superiorMoney" name="superiorMoney" value="" placeholder="请输入上级资金" class="layui-input" >
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认修改</button>
        </div>
    </div>
</div>

<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    function init(){
        var $ = layui.jquery

        // 2.获取用户当前的信息
        $.ajax({
            type: 'GET',
            url: $api + 'projectLibrary/enterprise/select/enterprise',
            contentType: "application/json;charset=utf-8",
            async: false,
            headers: {
                'Authorization': layui.data('table')['Authorization']
            },
            success: function (res) {

                // 2.1 根据查询到的数据对页面进行填充
                identifyCode(res)
                if (!res.code) {
                    $("#id").val(res.data.id);
                    $("#name").val(res.data.name);
                    $("#code").val(res.data.code);
                    $("#username").val(res.data.username);
                    $("#password").val(res.data.password);
                    $("#phone").val(res.data.phone);
                    $("#economics").val(res.data.economics);
                    $("#certification").val(res.data.certification);
                    $("#verify").val(getVerify(res.data.verify));
                    $("#municipalMoney").val(res.data.municipalMoney);
                    $("#superiorMoney").val(res.data.superiorMoney);
                }else{
                    layer.msg(res.message)
                }

            }
        });
    }
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            console.log(JSON.stringify(data.field))
            var index = layer.confirm("是否提交", {
                title: '最终的提交信息'
            }, function () {

                data.field.verify = getVerifyVo(data.field.verify)
                $.ajax({
                    type: 'POST',
                    url: $api + 'projectLibrary/enterprise/update/enterprise',
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(data.field),
                    dataType: 'json',
                    async: false,
                    headers: {
                        'Authorization': layui.data('table')['Authorization']
                    },
                    success: function (res) {
                        // 2.1 根据查询到的数据对页面进行填充
                        identifyCode(res)
                        if (!res.code) {
                            // 关闭弹出层
                            layer.close(index);
                            //返回上个页面
                            window.location.href = "enterprise.html"

                        }else{
                            layer.msg(res.message)
                        }

                    }
                });


            });

            return false;
        });

    });
</script>
</body>
</html>